﻿struct sometype{
BYTE ar[10];
};

struct struct1{
int a;		   
double b;
};

struct struct2{
sometype *x;
int y;
};

struct func_in_inout
{
struct2 *s2_;
struct1 s1_;
func_in_inout(struct2* s2,struct1 s1):s2_(s2),s1_(s1){}
func_in_inout(){}
template<class Archive>    
		void serialize(Archive & ar, const unsigned int )
		{
			ar & s2_;
			ar & s1_;
		}
};

template<class T>
void Serialize(DWORD TID,char* func_name,T &func_struct,vector<char> *buf)
{
	std::stringstream ss(ios_base::in | ios_base::out | ios_base::binary);
	boost::archive::text_oarchive oa(ss,1);
	vector<char> vec_func_name;
	vec_func_name.insert (vec_func_name.begin(), func_name, func_name+strlen(func_name)+1);

	oa.save_binary(&TID,sizeof(DWORD));	//Write Thread ID
	oa << vec_func_name;				//Write Func Name
	oa << func_struct;

	int length=ss.tellp();
	char *buffer=new char[length];
	ss.read(buffer,length);
	//cout<<buffer<<endl;
	buf->resize(length);
	memcpy(&(buf->at(0)),buffer,length);
	delete[]buffer;
}

void DeserializeStdHeader(DWORD *TID,char* func_name,vector<char> *buf)
{
	std::stringstream ss(&(buf->at(0)),ios_base::in | ios_base::out | ios_base::binary);
	boost::archive::text_iarchive ia(ss,1);
	vector<char> vec_func_name;

	ia.load_binary(TID,sizeof(DWORD));	//Read Thread ID
	ia >> vec_func_name;				//Read Func Name

	strcpy(func_name,&(vec_func_name.at(0)));//Extract Func Name from vector
}

template<class T>
void Deserialize(T &func_struct,vector<char> *buf)
{
	std::stringstream ss(&(buf->at(0)),ios_base::in | ios_base::out | ios_base::binary);
	boost::archive::text_iarchive ia(ss,1);
	vector<char> vec_func_name;
	DWORD TID;

	ia.load_binary(&TID,sizeof(DWORD));	//Read Thread ID
	ia >> vec_func_name;				//Read Func Name

	ia >> func_struct;	
}
